<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
/*用户列表*/
    public function userlist(){
        //调用模型层获取数据
        $usersmodel=M('users');
        //var_dump($usermodel);
        $users=$usersmodel->order('u_id desc')->select();
        //调用视图层显示数据
        $this->users=$users;

        $this->display();

    }   
/*用户密码重置*/
    public function editpswd($u_id){     
        $usersmodel=M('users');
        $usersmodel->u_pass="123456";//md5("123456");
        if(false!==$usersmodel->where("u_id=$u_id")->save()){
            $this->success('密码重置成功！');
        }else{
            $this->error('密码重置失败');
        }     
    }
   /*删除用户*/
    public function deluser(){
    //dump($_GET);
    //$id=$_GET['id'];
    //echo $id;
    $u_id=$_GET['u_id'];
    $userModel = M("users");
    $postModel=M('post');// 实例化User对象
    $activitynModel=M('activityn');
    $feedbackModel=M('feedback');
    $matchnModel=M('matchn');
    $trainnModel=M('trainn');
    $post=$postModel->table('post p,user u')->where("p.u_id=u.u_id ")->select();//查询外键所在表
    $activityn=$activitynModel->table('activityn a,user u')->where("a.u_id=u.u_id ")->select();//查询外键所在表
    $trainn=$trainnModel->table('trainn t,user u')->where("t.u_id=u.u_id ")->select();//查询外键所在表
    $matchn=$matchnModel->table('matchn m,user u')->where("m.u_id=u.u_id ")->select();//查询外键所在表
    $feedback=$feedbackModel->table('feedback f,user u')->where("f.u_id=u.u_id ")->select();//查询外键所在表
    $result=$postModel->where($u_id)->delete(); //删除外键表中数据
    $result=$activitynModel->where($u_id)->delete(); //删除外键表中数据
    $result=$trainnModel->where($u_id)->delete(); //删除外键表中数据
    $result=$matchnModel->where($u_id)->delete(); //删除外键表中数据
    $result=$feedbackModel->where($u_id)->delete(); //删除外键表中数据
    $user=$userModel->where("u_id=$u_id")->select();
    $result1=$userModel->where("u_id=$u_id")->delete(); // 删除id为5的用户数据
    if ($user[0]['u_pic']!='nopic.jpg') {
        $picPath='Public/Admin/photo/'.$user[0]['u_pic'];
        unlink($picPath);
    }
        if($result1){                    
            $this->success('删除成功');//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
            } else {
             $this->error('删除失败'); //错误页面的默认跳转页面是返回前一页，通常不需要设置
            }
    } 

    /*查看用户详情*/
    public function detail($u_id){
     $usermodel=M('users');
     $users=$usermodel->where("u_id = $u_id")->select(); 
     $this->users=$users;
     $this->display();
    } 
    

 public function collectlist(){
        //调用模型层获取数据
        $collectmodel=M('collect');
        //var_dump($usermodel);
        $collect=$collectmodel->table('vm_collect c,vm_users u')->where('c.u_id=u.u_id')->select();
        //调用视图层显示数据
        $this->collect=$collect;

        $this->display();

    } 

 


public function commentslist(){
        //调用模型层获取数据
        $commentsmodel=M('comments');
        //var_dump($usermodel);
        $comments=$commentsmodel->table('vm_comments c,vm_users u')->where('c.u_id=u.u_id')->select();
        //调用视图层显示数据
        $this->comments=$comments;

        $this->display();

    } 

 public function delcomments($com_id){
   
    $commentsModel = M("comments"); // 实例化User对象
    $comments=$commentsModel->where("com_id=$com_id")->select();
    $result=$commentsModel->where("com_id=$com_id")->delete(); 
        if($result){                    
            $this->success('删除成功');//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
            } else {
             $this->error('删除失败'); //错误页面的默认跳转页面是返回前一页，通常不需要设置
            }

    }



    }